import {page, pageFunc} from "../common/PageBuilder";
import {BasePage, BasePageData} from "../common/core/BasePage";
import {UserPage} from "../common/partPages/UserPage";
import {QueryPage} from "../common/partPages/QueryPage";
import {waitForLogin} from "../../modules/userModule/managers/UserManager";
import {waitForDataLoad} from "../../modules/coreModule/managers/DataManager";
import {TaskInterface} from "../../modules/taskModule/TaskCommon";
import {DataLoader, field} from "../../modules/coreModule/data/DataLoader";
import {TaskIndexData} from "../../modules/taskModule/data/Task";
import {UserIndexData} from "../../modules/userModule/data/User";

class Test extends BasePageData {

	@field([TaskIndexData])
	tasks: TaskIndexData[] = [];
	@field([UserIndexData])
	users: UserIndexData[] = [];
	@field
	tabIdx: number = 0;
}

@page("myFollow", "我的关注")
export class MyFollowPage extends BasePage<Test> {

	public data = new Test();

	/**
	 * 部分页
	 */
	public userPage: UserPage = new UserPage();
	public queryPage: QueryPage =
		new QueryPage(this.loadData.bind(this));

	onShow() {
		super.onShow();
		this.queryPage.refresh();
		this.setData({tabIdx: 0});
	}

	/**
	 * 数据回调，保证projectList和personList能从后端获取到
	 */
	@waitForLogin
	@waitForDataLoad
	private async loadData(queryParams) {
		const res = await TaskInterface.GetCollectTasks({
			...queryParams
		})
		const projectList = res.tasks?.map(
			t => DataLoader.load(TaskIndexData, t));
		return projectList && this.setData({tasks: projectList});
	}

	/**
	 * tab切换
	 */
	@pageFunc
	public onTabChange(e) {
		this.setData({tabIdx: e.detail.index});
	}

}
